package no.kolstad.movies.dao;

/**
 *  Copyright [2008] Christopher Kolstad
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
 * Unless required by applicable law or agreed to in writing, software distributed under the License 
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License. 
 */

import java.util.List;

/**
 * Generic interface for Data Access Objects.
 */
public interface BaseDAO<T> {
  /**
   * Persists the object.
   * 
   * @param object
   *          the object to save
   */
  void save(T object);

  /**
   * Loads an object by its id.
   * 
   * @param id
   *          the id to load
   * @return the object to load, or {@code null} if no such object exists
   */
  T get(Long id);

  /**
   * Removes the object with the given id from the persistent storage.
   * 
   * @param id
   *          the id to remove
   */
  void remove(Long id);

  /**
   * Removes the object from the persistent storage.
   * 
   * @param object
   *          the object to remove
   */
  void remove(T object);

  /**
   * Returns a {@code List} of all the objects this DAO is responsible for.
   * 
   * @return all the objects this DAO is responsible for
   */
  List<T> loadAll();

  /**
   * Reassociates the object with the underlying persistence layer.
   * 
   * @param object
   *          the object to reassociate
   * @throws UnsupportedOperationException
   *           if the persistence layer doesn't support this operation.
   */
  void reassociate(T object);
}
